<?php
/**
 *CouponController
 * @author tan bing
 * @date 2021-10-11 15:29
 */


namespace Modules\Coupon\Http\Controllers\Api;


use Modules\Coupon\Services\Api\CouponServices;

class CouponController extends ApiBaseController
{

    /**
     * @var CouponServices
     * @author tan bing
     */
    private CouponServices $couponServices;

    /**
     * CouponController constructor.
     *
     * @param CouponServices $couponServices
     * @author tan bing
     * @date 2021-10-14 11:13
     */
    public function __construct(CouponServices $couponServices)
    {
        $this->couponServices = $couponServices;
    }

    /**
     * 获取优惠券列表.
     * @return mixed
     * @author tan bing
     * @date 2021-10-11 16:19
     */
    public function getCouponList()
    {
        $result = $this->couponServices->getCouponList();
        return $this->success($result);
    }

    /**
     * 领取优惠券
     * @return mixed
     * @throws \Throwable
     * @author tan bing
     * @date 2021-10-14 15:29
     */
    public function receiveCoupon()
    {
        try {
            $result = $this->couponServices->receiveCoupon();
        } catch (\Exception $e) {
            return $this->failed($e->getMessage());
        }

        return $this->success($result);
    }

    /**
     * 获取用户优惠券列表
     * @return mixed
     * @author tan bing
     * @date 2021-10-14 15:42
     */
    public function getUserCouponList()
    {
        $result = $this->couponServices->getUserCouponList();
        return $this->success($result);
    }

}